﻿using System.Web;
using System.Web.UI;
using com.kmer.Security;

namespace com.kmer.Helper {
    public static class HtmlHelper {
		public static string HtmlEncode(this string str) {
			return string.IsNullOrWhiteSpace(str) ? str : HttpContext.Current.Server.HtmlEncode(str);
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="thePage"></param>
        /// <param name="message"></param>
	    public static void Alert(this Page thePage, string message){
	        thePage.ClientScript.RegisterClientScriptBlock(thePage.GetType(), MD5.Compute(message)
                ,$"alert('{message.Replace("'","\\'")}')",true);
	    }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="thePage"></param>
        /// <param name="message"></param>
        /// <param name="url"></param>
	    public static void AlertAndRedirect(this Page thePage, string message, string url)
	    {
            thePage.ClientScript.RegisterClientScriptBlock(thePage.GetType(), MD5.Compute(message+url)
                , $"alert('{message.Replace("'", "\\'")}');location.href='{url}';", true);
        }
	}
}
